#! /usr/bin/env python
from pywslib import *
import sys
pyws = pywslib()
tuser = "admin"
tpassword = "admin"
pyws.header()
funct = 0
user = 0
try:
	user = pyws.COOKIE["user"]
except:
	pass
try:
	funct = pyws.GET["funct"]
except:
	pass

if not funct:
	pyws.header()
	if user:
		print "Benvenuto "+user+" (<a href='login.py?funct=esci'>Esci</a>)<br /><br />"
	else:
		print "Non sei ancora loggato<br /><br />"
	print '''
	<form action='login.py?funct=login' method='POST'>
	User : <input type='text' name='user'><br />
	Pass : <input type='text' name='pass'><br />
	<input type='submit' value='Login'>
	</form>
	'''
	sys.exit()
	
if funct == "login":
	try:
		user = pyws.POST["user"]
		password = pyws.POST["pass"]
	except:
		sys.exit()
	if tuser == user and tpass == password:
		pyws.setcookie("user",user)
		pyws.setcookie("pass",password)
		pyws.header()
		print "Loggato, torna <a href='login.py'>indietro</a>"
